#include <header.h>
#include <iostream>

using std::cout;
using std::endl;

int main()
{
    const char *port = "1280";
    const char *ip = "127.0.0.1";

    int sockfd = socket(AF_INET,SOCK_STREAM,0);

    struct sockaddr_in sock;
    sock.sin_family = AF_INET;
    sock.sin_port = htons(atoi(port));
    sock.sin_addr.s_addr = inet_addr(ip);

    connect(sockfd,(const struct sockaddr*)&sock,sizeof(sock));
    
    while(1){
        char buff[100];
        ssize_t ret = read(STDIN_FILENO,buff,sizeof(buff));
        send(sockfd,buff,ret,0);
        
        memset(buff,sizeof(buff),0);
        ret = recv(sockfd,buff,sizeof(buff),0);
        if(ret == 0)
        {
            printf("对方断开连接");
            break;
        }
        printf("buf : %s\n",buff);
    }
#if 0
    while(1){
        struct sockaddr_in client;
        socklen_t len = sizeof(client);

        int netfd = accept(sockfd,(struct sockaddr*)&client,&len);

    }
#endif

    close(sockfd);
    return 0;
}

